/*
 * Copyright 2011 Biz-e (info@biz-e.nl)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.bize.knexions.android.knexion;

import nl.bize.knexions.android.AndroidKnexionsActivity;
import android.app.Activity;
import android.content.Intent;

/**
 * Abstract implementation of the {@link Controller} interface.
 * Takes care of some basic functionality
 * 
 * @author Joost A. Bloemsma
 */
public abstract class AbstractController implements Controller {
	private Class<? extends Activity> mainActivityCls = null;
	private Class<? extends Activity> registerActivityCls = null;
//	private Activity mainActivity = null;
//	private Activity registerActivity = null;
	private String name = null;
	private String instanceName = null;
	private AndroidKnexionsActivity androidKnexionsActivity;
	
	protected AbstractController(String name, Class<? extends Activity> mainActivityCls) {
		this.mainActivityCls = mainActivityCls;
		this.name = name;
	}
	
	/**
	 * {@inheritDoc}
	 */
	public void register() {
		Intent i = new Intent(androidKnexionsActivity, getRegisterActivityCls());
		androidKnexionsActivity.startActivity(i);
	}

	public void init(AndroidKnexionsActivity androidKnexionsActivity) {
		this.androidKnexionsActivity = androidKnexionsActivity;
	}
	
	/**
	 * {@inheritDoc}
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * {@inheritDoc}
	 */
	public String getInstanceName() {
		return this.instanceName;
	}
	
	/**
	 * @return the mainActivityCls
	 */
	protected Class<? extends Activity> getMainActivityCls() {
		return mainActivityCls;
	}

	/**
	 * @param mainActivityCls the mainActivityCls to set
	 */
	protected void setMainActivityCls(Class<? extends Activity> mainActivityCls) {
		this.mainActivityCls = mainActivityCls;
	}

	/**
	 * @return the registerActivityCls
	 */
	protected Class<? extends Activity> getRegisterActivityCls() {
		return registerActivityCls;
	}

	/**
	 * @param registerActivityCls the registerActivityCls to set
	 */
	protected void setRegisterActivityCls(Class<? extends Activity> registerActivityCls) {
		this.registerActivityCls = registerActivityCls;
	}

//	/**
//	 * @return the mainActivity
//	 */
//	protected Activity getMainActivity() {
//		return mainActivity;
//	}
//
//	/**
//	 * @return the registerActivity
//	 */
//	protected Activity getRegisterActivity() {
//		return registerActivity;
//	}

	/**
	 * @param name the name to set
	 */
	protected void setName(String name) {
		this.name = name;
	}

	/**
	 * @param instanceName the instanceName to set
	 */
	protected void setInstanceName(String instanceName) {
		this.instanceName = instanceName;
	}

}

